import React, { useEffect, useState, useCallback } from "react";
export const defaultSkuList = [
	{
		id: "1763088444881621078",
		spuId: "51",
		image: "https://img.17mjf.com/images/crawler/20220319/20220319151638524.jpg",
		spuCode: "YGM803",
		skuCode: "YGM803-001",
		skuName: "2019雲归梦全棉活性大版四件套-中国风花卉风格盛世牡丹",
		skuAbbreviation: "床垫褥子四件套",
		colorSpecifications: "音澜-白金;1.5m床（床单款）",
		specs: "1.5m床（床单款）",
		colour: "音澜-白金",
		type: 1,
		retailPrice: 130,
		purchasePrice: 100,
		costPrice: 50,
		weight: 3,
		status: 1,
		note: "备注说明",
		runningVolumeStatus: 0,
		createTime: "2024-03-08 07:12:41",
		updateTime: "2024-03-19 03:04:14",
		isMatch: 1,
		isManyGoods: 1,
		matchOrNot: 1,
		imageType: 1,
		combinationSubList: [],
		goodsSkuMatches: [
			{
				id: "1767492377339432962",
				skuId: "1763088444881621078",
				matchType: 2,
				supplierId: "2",
				supplierName: "供应商top",
				supplierSkuId: "445963384",
				supplierSkuCode: "RITDD-001",
				supplierSkuName: "100支全棉贡缎绣花四件套",
				supplierSkuImage: "https://img.17mjf.com/images/crawler/20220606/20220606124602812440866.jpg",
				supplierSpuCode: "RITDD",
				isDefault: 0
			},
			{
				id: "1768115753422602242",
				skuId: "1763088444881621078",
				matchType: 1,
				supplierId: "42",
				supplierName: "供应商top",
				isDefault: 0
			},
			{
				id: "1767492377339432962",
				skuId: "1763088444881621078",
				matchType: 2,
				supplierId: "2",
				supplierName: "供应商top",
				supplierSkuId: "445963384",
				supplierSkuCode: "RITDD-001",
				supplierSkuName: "100支全棉贡缎绣花四件套",
				supplierSkuImage: "https://img.17mjf.com/images/crawler/20220606/20220606124602812440866.jpg",
				supplierSpuCode: "RITDD",
				isDefault: 0
			},
			{
				id: "1768115753422602242",
				skuId: "1763088444881621078",
				matchType: 1,
				supplierId: "42",
				supplierName: "供应商top",
				isDefault: 0
			}
		]
	},
	{
		id: "1763088444881621079",
		spuId: "51",
		image: "https://img.17mjf.com/images/crawler/20240223/7f2779674dcb4b71a83c038aafdf8d15_169x225.jpg",
		spuCode: "YGM803",
		skuCode: "YGM803-002",
		skuName: "2019雲归梦全棉活性大版四件套-中国风花卉风格盛世牡丹",
		skuAbbreviation: "床垫褥子四件套",
		colorSpecifications: "盛世牡丹;1.5m床（床单款）",
		specs: "1.5m床（床单款）",
		colour: "盛世牡丹",
		type: 1,
		retailPrice: 130,
		purchasePrice: 200,
		costPrice: 50,
		weight: 3,
		status: 1,
		productIngredients: "11111",
		runningVolumeStatus: 0,
		createTime: "2024-03-08 07:12:41",
		updateTime: "2024-03-19 03:07:05",
		isMatch: 1,
		isManyGoods: 1,
		matchOrNot: 1,
		imageType: 1,
		combinationSubList: [],
		goodsSkuMatches: [
			{
				id: "1767742198008733698",
				skuId: "1763088444881621079",
				matchType: 2,
				supplierId: "2",
				supplierName: "供应商top1",
				supplierSkuId: "3737649",
				supplierSkuCode: "RITDD-002",
				supplierSkuName: "100纯棉刺绣四件套全棉绣花高级感长绒棉床单棉维也纳",
				supplierSkuImage: "https://img.17mjf.com/images/crawler/20220606/20220606124602812440866.jpg",
				supplierSpuCode: "RITDD",
				isDefault: 0
			},
			{
				id: "1768115753493905410",
				skuId: "1763088444881621079",
				matchType: 1,
				supplierId: "42",
				supplierName: "供应商top",
				isDefault: 0
			},
			{
				id: "1767742198008733698",
				skuId: "1763088444881621079",
				matchType: 2,
				supplierId: "2",
				supplierName: "供应商top1",
				supplierSkuId: "3737649",
				supplierSkuCode: "RITDD-002",
				supplierSkuName: "100纯棉刺绣四件套全棉绣花高级感长绒棉床单棉维也纳",
				supplierSkuImage: "https://img.17mjf.com/images/crawler/20220606/20220606124602812440866.jpg",
				supplierSpuCode: "RITDD",
				isDefault: 0
			},
			{
				id: "1768115753493905410",
				skuId: "1763088444881621079",
				matchType: 1,
				supplierId: "42",
				supplierName: "供应商top",
				isDefault: 0
			}
		]
	}
];

export const getUniqueListByKey = (arr, key, needKey) => {
	const result = [];
	const map = new Map();
	if (needKey) {
		arr.sort((a, b) => {
			if (a[needKey]) return -1;
			if (b[needKey]) return 1;
		});
	}

	for (const item of arr) {
		if (!map.has(item[key])) {
			map.set(item[key], true); // set any value to Map
			result.push(item);
		}
	}
	return result;
};

export const filterMatch = arr => {
	return arr.filter(item => item.isMatch);
};

export function removeSpacesAndConvertToLowerCase(str) {
	return str.replace(/\s+/g, "").toLowerCase();
}

// 示例使用
// var originalStr = " Hello World! ";
// var resultStr = removeSpacesAndConvertToLowerCase(originalStr);
// console.log(resultStr); // 输出: "helloworld!"
